package mittens.skat;


public class Game {
	
	public Game( ){
		deck_ = new Deck();
		dealCards();
	}
	
	private void dealCards( ){
		hands_[0] = new Hand();
		hands_[1] = new Hand();
		hands_[2] = new Hand();
		
		hands_[0].add(deck_.dealTopN(3));
		hands_[1].add(deck_.dealTopN(3));
		hands_[2].add(deck_.dealTopN(3));
		
		theSkat_ = new Skat(deck_.dealTopN(2));
		
		hands_[0].add(deck_.dealTopN(4));
		hands_[1].add(deck_.dealTopN(4));
		hands_[2].add(deck_.dealTopN(4));
		
		hands_[0].add(deck_.dealTopN(3));
		hands_[1].add(deck_.dealTopN(3));
		hands_[2].add(deck_.dealTopN(3));
		
		
	}
	
	public void setTrump( int trumpSuit ){
		hands_[0].setTrump(trumpSuit);
		hands_[1].setTrump(trumpSuit);
		hands_[2].setTrump(trumpSuit);
	}
	
	public void sortHands( ){
		hands_[0].sort();
		hands_[1].sort();
		hands_[2].sort();
	}
	
	public String toString( ){
		StringBuffer buf = new StringBuffer();
		for( int i=0; i < hands_.length; i++ ){
			buf.append("Player"+(i+1)+" hand:\n");
			buf.append(hands_[i].toString()+"\n");
		}
		
		buf.append("The Skat:\n");
		buf.append(theSkat_.toString());
		return buf.toString();
	}
	
	public void setType( int type ){
		if( type != REGULAR && type != NULL && type != RAMSHT ){
			throw new IllegalArgumentException( "Illegal game type: "+type);
		}
		type_ = type;
	}
	
	
	private int type_;
	//private int nPlayers_; ONLY THREE PLAYERS for now at least
	
	private Deck deck_;
	private Hand[] hands_ = new Hand[3];
	private Skat theSkat_;
	
	public static final int REGULAR = 1;
	public static final int    NULL = 2;
	public static final int  RAMSHT = 4;
}
